package graphSample;

import java.util.HashMap;

import core.Entity;
import core.Graph;
import core.Process;

public class PaperPusher {
	static public Graph getGraph(){
		Graph g = new Graph("PaperPusher");
		
		// Entities
		
		Entity e1 = new Entity(g, "In");
		e1.addVariable("$band","INT");
		e1.addVariable("$aTime","DOUBLE");
		e1.addVariable("$pTime","DOUBLE");
		e1.addVariable("$lTime","DOUBLE");
		
		Entity e2 = new Entity(g, "Out");
		e2.addVariable("$lBand","INT");
		e2.addVariable("$uTime","DOUBLE");
		
		// Processes
		Process p1 = new Process(g, "promote", "$pTime<$lTime AND $band<4 AND $pTime<10000");
		p1.addEntityIn(e1);
		p1.addEntityOut(e1);
		p1.addEvalItem("$aTime=$pTime");
		p1.addEvalItem("$band=$band+1");
		p1.addEvalItem("If[$band==2,$pTime=$aTime+Ceiling[Log[RandomReal[]]/Log[1-0.01]];$lTime=$aTime+Ceiling[Log[RandomReal[]]/Log[1-0.008]]]");
		p1.addEvalItem("If[$band==3,$pTime=$aTime+Ceiling[Log[RandomReal[]]/Log[1-0.005]];$lTime=$aTime+Ceiling[Log[RandomReal[]]/Log[1-0.02]]]");
		p1.addEvalItem("If[$band==4,$pTime=100000;$lTime=$aTime+Ceiling[Log[RandomReal[]]/Log[1-0.01]]]");
		
		Process p2 = new Process(g, "leave", "$pTime>=$lTime AND $lTime<10000");
		p2.addEntityIn(e1);
		p2.addEntityOut(e1);
		p2.addEntityOut(e2);
		p2.addEvalItem("$band=1");
		p2.addEvalItem("$uTime=$lTime");
		p2.addEvalItem("$lBand=$band");
		p2.addEvalItem("$aTime=$lTime");
		p2.addEvalItem("$pTime=$aTime+Ceiling[Log[RandomReal[]]/Log[1-0.03]]");
		p2.addEvalItem("$lTime=$aTime+Ceiling[Log[RandomReal[]]/Log[1-0.02]]");
		
		//Add token in e1
		HashMap<String,String> token;
		for(int i=0;i<100;i++){
			token = new HashMap<String,String>();
			token.put("$band", "1");
			token.put("$aTime", "0");
			token.put("$pTime", String.valueOf((int) Math.ceil(Math.log(Math.random())/Math.log(1-0.03))));
			token.put("$lTime", String.valueOf((int) Math.ceil(Math.log(Math.random())/Math.log(1-0.02))));
			e1.addToken(token);
		}
		
		return g;
	}
}
